package com.blb.community.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.community.Annotation.Log;
import com.blb.community.entity.ZyRoom;
import com.blb.community.service.IZyCommunityService;
import com.blb.community.service.IZyRoomService;
import com.blb.community.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 房间  前端控制器
 * </p>
 *
 * @author 帅帅
 * @since 2022-07-02
 */
@Api(tags = "房屋模块")
@CrossOrigin
@RestController
@RequestMapping("/zyRoom")
public class ZyRoomController {

    @Autowired
    private IZyRoomService zyRoomService;

    /**
     * 分页查询
     *
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public ResponseResult<IPage<ZyRoom>> selectRoomPage(Long current) {
        System.out.println(current);
        return ResponseResult.ok(zyRoomService.selectRoomPage(current, 3L));
    }

    @ApiOperation("模糊分页查询")
    @GetMapping("/page/fuzzy")
    public ResponseResult<IPage<ZyRoom>> fuzzyPage(Long current, Long size, String roomStatus, String communityName, String unitName, String buildingName) {
        return ResponseResult.ok(zyRoomService.fuzzyPage(current, size, roomStatus, communityName, unitName, buildingName));
    }


    //查询所有
    @ApiOperation("查询所有")
    @GetMapping("")
    public ResponseResult<List<String>> getzyrooms() {
        List<ZyRoom> list = zyRoomService.list(null);
        ArrayList<String> statuslist = new ArrayList<>();
        for (ZyRoom zyRoom : list) {
            String s = zyRoom.getRoomStatus();
            statuslist.add(s);
        }

        return ResponseResult.ok(statuslist);
    }
    @Log(module = "添加", operationType = 1, requestMethod = "POST")
    @ApiOperation("添加")
    @PostMapping("")
    public ResponseResult<String> addzyroom(@RequestBody ZyRoom zyRoom) {
        zyRoom.setCommunityId(1338423709557272577L);
        zyRoomService.save(zyRoom);
        return ResponseResult.ok("添加成功");
    }
    @Log(module = "修改", operationType = 2, requestMethod = "PUT")
    @ApiOperation("修改")
    @PutMapping("")
    public ResponseResult<String> update(@RequestBody ZyRoom zyRoom) {
        zyRoom.setCommunityId(1338423709557272577L);
        zyRoomService.updateById(zyRoom);
        return ResponseResult.ok("修改成功");
    }
    @Log(module = "删除", operationType = 3, requestMethod = "DELETE")
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseResult<String> delete(@PathVariable long id) {
        zyRoomService.removeById(id);
        return ResponseResult.ok("删除成功");
    }
}
